package com.calcgpa.util;

import java.util.List;

import com.calcgpa.core.vo.Score;

public class CalcGPAMethod {

	public Double doCalc(List<Score> scores, boolean isPE){
		double totalCredit = 0;
		double totalPoint = 0;
		
		for (Score score:scores){
			if (score.getType().indexOf("公选课") != -1) continue;
			if (score.getCourse().indexOf("体育") != -1){
				if (isPE) {
					totalCredit+=score.getCredit();
					totalPoint+=getGP(score.getScore()) * score.getCredit();					
				} else continue;
			}
			totalCredit+=score.getCredit();	
			totalPoint+=getGP(score.getScore()) * score.getCredit();	
		}
		if (totalCredit == 0) return 0.0;
		return totalPoint/totalCredit;
	}
	
	private Double getGP(Double score){
		if (score >= 60){
			return (score - 50)/10;
		} else {
			return 0.0;
		}
	}
}
